// 安装 ts-node或tsx 执行 npx ts-node test.ts或npx tsx test.ts或node --import=tsx test.ts
import { queryDdckDb } from "./mysqlTest";
import * as util from "node:util";
import * as fs from "node:fs/promises";

const a = "123";
const b = parseInt(a);
console.log(b);

const c = [1, 2, 3];
const d = c.reduce((pre, item, index, arr) => {
    return pre + item;
}, "0");

type User = {
    name: string;
    age: number;
};

function isAdult(user: User): boolean {
    return user.age >= 18;
}

const justine = {
    name: "Justine",
    age: 23,
} satisfies User;

const isJustineAnAdult = isAdult(justine);
console.log(isJustineAnAdult);

queryDdckDb();

console.log(util.format("abcdef"));

async function fileOp() {
    const path = "E:\\nodeWriteFile.txt"
    try {
        await fs.access(path, fs.constants.F_OK);
    } catch (err) {
        console.log("文件不存在，创建");
        await fs.writeFile(path, "abcdefg");
    }
    const a = await fs.readFile(path, "utf8");
    console.log(a);
}
fileOp();
